/**
 * 	Gestione Colonna menu + Corpo a destra
 */

var $ = jQuery;
$(document).ready(function() {
/***************************************************   GESTIONE WAYPOINT  ***************************************/
	
	$('.slide').waypoint(function(direction) {
	  if(direction == 'down'){	
		idSelected = $(this).attr('id');
		arr = idSelected.split('_');
		$('.navigation .point').removeClass('selected');
		$('.navigation .point').removeClass('visited');
		selected = parseInt(arr[1]);		
		
		//$('#point_'+selected).addClass('selected visited');
		
		for(i=0; i<=selected; ++i){
			$('#point_'+i).addClass('selected');
			if(i>0){
				$('#point_'+(i-1)).addClass('visited');
			}
		}
	  }
	},
	{ offset: '25%' }
  ).waypoint(function(direction) {
	  if(direction == 'up'){
		idSelected = $(this).attr('id');
		arr = idSelected.split('_');
		$('.navigation .point').removeClass('selected');
		$('.navigation .point').removeClass('visited');
		selected = parseInt(arr[1]);		
		
		//$('#point_'+selected).addClass('selected visited');
		
		for(i=0; i<=selected; ++i){
			$('#point_'+i).addClass('selected');
			if(i>0){
				$('#point_'+(i-1)).addClass('visited');
			}
		}
	  }
	},
	{ offset: '15%' }
  );
	
	
/***************************************************   GESTIONE WAYPOINT  ***************************************/
	
/**************************************** GESTIONE CLICK EVENT WAYPOINT ******************************************/
	
	$('#menu_navigazione.contenuto div.navigation a.point').click(function () {
		var h = 120;
		dataslide = $(this).attr('href').replace('#','');
		if(dataslide == 'slide_0') {
			h = 45;
		}
		menuHeight = $(".navigation").outerHeight(true)-1; // Calculate .menu height and then subtract by 1px to compensate for browser rounding (when the slide heights aren't whole numbers).
		goToByScroll(dataslide, menuHeight, h);
	});
	function goToByScroll(dataslide, menuHeight, h) {
        $("html, body").animate({
            scrollTop: $('.slide[id="' + dataslide + '"]').offset().top + h - menuHeight
            }, 500);    
        console.log($('.slide[id="' + dataslide + '"]').offset().top + h - menuHeight);
    }
/****************************************GESTIONE CLICK EVENT WAYPOINT ******************************************/	
	

/***************************************************   /GESTIONE HEADER DINAMICO  ***************************************/	
	
	$('.left li:has(a.active)').after($('#menu_navigazione'));
	$('.left li:has(a.active)').css('font-weight', '700');
	
/***************************************************   /GESTIONE HEADER DINAMICO  ***************************************/
	
	
	
/***************************************************   /GESTIONE FOOTER DINAMICO  ***************************************/

$('.footer').css('margin-top', $('.corpo_centrale .left').height() - 99);

/***************************************************   /GESTIONE FOOTER DINAMICO  ***************************************/



/***************************************************   GESTIONE HEADER DINAMICO + PULSANTE TOP  ***************************************/


	$('.go-top').click(function () {
		$("html, body").animate({scrollTop:0},400);
	});
	
	/*
	$('.right').waypoint(
		function(direction) {
			if (direction == 'down'){
				$(".header").addClass("fixed", 500);
				$(".header .logo").addClass("fixed", 500);
				$(".left").addClass("fixed", 10000);
				if($("#menu_navigazione").length != 0) {
					$('#menu_navigazione').show(600);
					$('.item-list li').not($('li:has(a.active)')).hide(600);
				}
				$('.go-top').offset({ left: $('.container').position().left + $('.container').width() - 45});
				$('.go-top').animate({
					bottom: 30
					}, 400, function() {}
				);
			} else {
				$(".header").removeClass("fixed", 300);
				$(".left").removeClass("fixed", 300);
				if($("#menu_navigazione").length != 0) {
					$('#menu_navigazione').hide(600);
					$('.item-list li').not($('li:has(a.active)')).show(600);
				}
				$('.go-top').animate({
					bottom: -30
					}, 400, function() {}
				);
			}
		}
		,{ offset: 175 }
	);
	*/
	
/***************************************************   /GESTIONE HEADER DINAMICO + PULSANTE TOP  ***************************************/
	
});	// Fine onload
